<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['article']['tab'], 'list');?>
		</div>
	</div>
</div>

<div class="row">
	<form action="<?php echo url('article-list');?>" method="GET">
		<div class="col-md-2 m-b-sm">
			<select name="cid" class="form-control">
				<option value="0">分类</option>
				<?php foreach($catalog as $c){ ?>
				<option value="<?php echo $c['id'];?>" <?php if($cid==$c['id']){echo 'selected';}?>><?php echo $c['name'];?></option>
				<?php } ?>
			</select>
		</div>
		<div class="col-md-3 m-b-sm">
			<input type="text" name="title" placeholder="标题" value="<?php echo $title!='all' ? $title : ''; ?>"  class="form-control" />
		</div>
		<div class="col-md-2 m-b-sm">
			<button id="search" class="form-control btn btn-primary">搜索</button>
		</div>
	</form>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">删除</th>
							<th class="text-center">ID：</th>
							<th class="text-center">标题</th>
							<th class="text-center">分类</th>
							<th class="text-center">时间</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						<?php if($article){foreach($article as $a){ ?>
						<?php $c = db_find_one('article_catalog', array('id'=>$a['cid'])); ?>
						<tr uid="<?php echo $a['id']; ?>">
							<td class="text-center"><input type="checkbox" name="delete" /></td>
							<td class="text-center"><?php echo $a['id']; ?></td>
							<td class="text-center"><?php echo $a['title']; ?></td>
							<td class="text-center"><?php echo $c['name']; ?></td>
							<td class="text-center"><?php echo date('m-d H:i',$a['time']); ?></td>
							<td class="text-center">
								<a href="<?php echo url("article-update-$a[id]"); ?>">编辑</a>
							</td>
						</tr>
						<?php }} ?>
					</tbody>
				</table>
			</div>
			<hr class="m-t-0" />
			<p><button class="btn btn-sm m-l-1" id="confirm">删除</button></p>
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>



<script>
var jbody = $("#userbody");
var jconfirm = $("#confirm");
var jsearch = $("#search");
var jsrchtype = $("#srchtype");
var jkeyword = $('#keyword');
var juserlist = $('#userlist');

// 删除选中的用户
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的文章");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		$.xpost(xn.url('article-delete'), {id:uid}, function(code, message) {
			if(code != 0) return $.alert(message);
			jtr.remove();
		});
	});
});

$('#nav_pc li.article, #nav_mobile li.article').tab('show');
</script>